package br.com.felipeab.dexter.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Classe ServiceOrder
 * 
 * @author Felipe A. Braga <br>
 *         18/06/2012 00:47:19<br>
 * 
 */
@Entity
@Table(name = "tServiceOrder")
public class ServiceOrder implements Serializable {

	private static final long serialVersionUID = -966611872293378137L;

	private Long id;
	private String description;
	private Date dateSolicitation;
	private Date datePrevision;
	private Date closingDate;
	private User solicitant;
	private User solicited;
	private Status statusOS;
	private List<DetailSolicitation> details;

	public ServiceOrder() {}

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id", nullable = false)
	public Long getId() {
		return id;
	}

	public void setId(Long codigo) {
		this.id = codigo;
	}

	@Column(name = "description", nullable = false, length = 255)
	public String getDescription() {
		// if (!StringHelper.isEmpty(description)) {
		// description = description.trim();
		// }
		return description;
	}

	public void setDescription(String descricao) {
		this.description = descricao;
	}

	@Column(name = "dateSolicitation", nullable = false)
	@Temporal(TemporalType.TIMESTAMP)
	public Date getDateSolicitation() {
		return dateSolicitation;
	}

	public void setDateSolicitation(Date dataSolicitacao) {
		this.dateSolicitation = dataSolicitacao;
	}

	@Column(name = "datePrevision", nullable = false)
	@Temporal(TemporalType.TIMESTAMP)
	public Date getDatePrevision() {
		return datePrevision;
	}

	public void setDatePrevision(Date dataPrevisao) {
		this.datePrevision = dataPrevisao;
	}

	@Column(name = "closingDate")
	@Temporal(TemporalType.TIMESTAMP)
	public Date getClosingDate() {
		return closingDate;
	}

	public void setClosingDate(Date dataEncerramento) {
		this.closingDate = dataEncerramento;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "usrSolicitant", referencedColumnName = "id", nullable = false)
	public User getSolicitant() {
		return solicitant;
	}

	public void setSolicitant(User solicitant) {
		this.solicitant = solicitant;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "usrSolicited", referencedColumnName = "id", nullable = false)
	public User getSolicited() {
		return solicited;
	}

	public void setSolicited(User solicitado) {
		this.solicited = solicitado;
	}

	@Column(name = "statusOS", nullable = false)
	@Enumerated(EnumType.STRING)
	public Status getStatusOS() {
		return statusOS;
	}

	public void setStatusOS(Status statusOS) {
		this.statusOS = statusOS;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "serviceOrder", cascade = { CascadeType.ALL })
	public List<DetailSolicitation> getDetails() {
		return details;
	}

	public void setDetails(List<DetailSolicitation> details) {
		this.details = details;
	}
}
